<!--
* @FileDescription: 医生数据修正
* @Date: 2022年11月21日 16:37:37
* TODO:
* [] Demo
-->

<template>
	<div class="fixTable">
		<el-button style="margin-bottom: 20px" type="danger" @click="deleteRow">
			批量删除
		</el-button>
		<el-table :data="doctorData.data" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column type="index" label="序号" />
			<el-table-column prop="customerId" label="患者编号"> </el-table-column>
			<el-table-column prop="customerName" label="患者姓名"> </el-table-column>
			<el-table-column prop="counterName" label="诊室名称"> </el-table-column>
			<el-table-column prop="reportTime" label="报到时间"> </el-table-column>
			<el-table-column prop="callTime" label="就诊时间"> </el-table-column>
			<el-table-column prop="waitTime" label="等候时长">
				<template slot-scope="scope">
					{{ hanldeTime(scope.row.waitTime) }}
				</template>
			</el-table-column>
			<el-table-column prop="staffName" label="医生姓名"> </el-table-column>
			<el-table-column prop="overTime" label="过号时间"> </el-table-column>

			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button type="text" @click="deleteRow(scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--  v-show="queueStatList.total > 0"-->
		<pagination
			:total="doctorData.total"
			:page.sync="query.current"
			:limit.sync="query.size"
			@pagination="pageChange"
		/>
	</div>
</template>

<script>
import {
	staffCounterDetail,
	delCountData,
	getStaffAllData,
} from '@/api/qbs/queueStat'

export default {
	name: 'Demo',
	components: {},
	// filters:{},
	// mixins:[],
	props: {
		counterId: { type: String, default: '' },
		staffId: { type: String, default: '' },
		queryParams: { type: Object, default: {} },
	},
	data() {
		return {
			doctorData: {},
			selections: [],
			query: { current: 1, size: 10 },
		}
	},
	// computed:{},
	watch: {
		// staffId(val) {
		// 	this.getDetailList(this.query)
		// },
		// counterId() {
		// 	this.getDetailList(this.query)
		// },
	},
	mounted() {
		this.query.beginTime = this.queryParams.beginTime
		this.query.endTime = this.queryParams.endTime
		this.getDetailList(this.query)
	},
	methods: {
		hanldeTime(data) {
			if (data) {
				let second = data % 60
				let minute = Math.floor(data / 60) % 60
				let hour = Math.floor(data / 3600)
				return `${hour}小时${minute}分钟${second}秒`
			} else {
				return ''
			}
		},
		// 删除
		async deleteRow(data) {
			let ids = []
			if (data.id) {
				// 删除当前行
				ids.push(data.id)
			} else {
				// 删除选中
				this.selections.forEach((item) => {
					ids.push(item.id)
				})
			}
			if (ids.length) {
				this.$confirm('确认删除？').then(async (_) => {
					await delCountData({ ids: ids.join(',') })
					this.$message({ type: 'success', message: '删除成功' })
					this.getDetailList()
				})
			} else {
				this.$message({ type: 'warning', message: '请选择要删除的项' })
			}
		},
		// 处理选中
		handleSelectionChange(selection) {
			this.selections = selection
		},
		// 页码变化
		pageChange(size) {
			this.query.size = size.limit
			this.query.current = size.page
			this.getDetailList(this.query)
		},
		// 获取医生详细数据
		async getDetailList(params = {}) {
			if (this.counterId) {
				this.doctorData = await staffCounterDetail(
					Object.assign(params, {
						staffId: this.staffId,
						counterId: this.counterId,
					})
				)
			} else {
				this.doctorData = await getStaffAllData(
					Object.assign(params, { staffId: this.staffId })
				)
			}
		},
	},
}
</script>
<style lang="scss" scoped></style>
